package com.vdongchina.thread.Concurrent;


import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

/**
 * 并发编程 - concurrentHashMap
 *
 * 锁的分段技术可有效提升并发访问率
 *
 * 多线程环境下,hashMap的put操作会引起死循环
 *
 *  http://www.importnew.com/28263.html
 *
 */
public class ConcurrentHashMapDemo {


    public static void main(String[] args) {
        Map map = new HashMap();
        System.out.println(map.put("yiyongyao",15));
        System.out.println(map.put("yiyongyao",17));
        // hashMapPut();

    }

    //环形链表产生的原因 https://blog.csdn.net/qq_21993785/article/details/80384250
   public static void hashMapPut()  {
       final HashMap map = new HashMap(2);
       Thread t = new Thread(new Runnable() {
           @Override
           public void run() {
               for(int i = 0 ;i<1000;i++)
               {
                   new Thread(new Runnable() {
                       @Override
                       public void run() {
                           map.put(UUID.randomUUID().toString(),"");
                           System.out.println("子线程----");

                       }
                   },"ftf"+i).start();
               }
           }
       },"ftf");
       t.start();
       try {
           t.join();
       } catch (InterruptedException e) {
           e.printStackTrace();
       }
       System.out.println("主线程");
   }

}
